package com.sqly.doc;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sqly.doc.pojo.Person;
import com.sqly.doc.util.BinderPojo;
import com.sqly.doc.util.BinderUtil;

public class NewActivity extends AppCompatActivity {
    private EditText id;
    @BinderPojo(value = R.id.name, name = "name", pojoProperty= true, require = true, promptMsg="请输入姓名")
    private EditText name;
    @BinderPojo(value = R.id.phone, name = "phone", pojoProperty= true, regex = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$", promptMsg="请输入正确的电话号码")
    private EditText phone;
    @BinderPojo(value = R.id.uname)
    private TextView uname;
    @BinderPojo(value = R.id.title)
    private TextView title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_activity);
        //通过反射+注解拿到每个控件的ID
        BinderUtil.exeFindById(NewActivity.this);
        title.setText("测试");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Person person = new Person();
                BinderUtil.copyDataToView(NewActivity.this, person);
                System.out.println("person property:"+person.getName()+":"+person.getPhone());
            }
        });

    }
}
